<template>
	<view class="notice-detail-container">
		<view class="detail">
			
				<view class="title">{{notice.noticeTitle}}</view>
				<view class="info">
					<view class="time">发布时间：{{notice.creationTime}}</view>
					<view class="author">发布人：{{notice.founder}}</view>
				</view>
				
				<view class="stauts">
					<u-tag :text="notice.state===1?'发布中':'暂停发布'"
					       :type="notice.state===1?'success':'error'">
					</u-tag>
				</view>
		</view>
		<view class="content">
			<view  v-html="notice.releaseStatus">
				
			</view>
		</view>
		<view class="image">
			<u-image :src="'http://1.12.48.84:8283'+'/neuedu-admin'+notice.imagersUpload" radius="15"></u-image>
		</view>
		<view class="state-info">
			<u-button :text="notice.state===1?'暂停发布':'发布中'" :type="notice.state===1?'error':'success'" @click="changeState(notice.state)"></u-button>
		</view>
		<MyButton buttonText="zhan" buttonStyle="error" @deal="pause"></MyButton>
	</view>
</template>

<script>
	import MyButton from '../../components/MyButton/MyButton.vue'
	export default {
		components:{
			MyButton
		},
		data() {
			return {
				id:0,
				notice:{
					imagersUpload:''
				},
				
			};
		},
		onLoad(option) {
			console.log(option.id)
			this.id=option.id
			this.getNoticeDetail()
		},
		methods:{
			pause(){
				console.log('pause')
			},
			changeState(state){
				var myState = state ===1?2:1
				uni.request({
					url: 'https://www.gzzyue.com/prod-api/system/campusNotice',
					method: 'PUT',
					data:{
						id:this.id,
						state:myState
					},
					header: {
						'Authorization': uni.getStorageSync("token") //自定义请求头信息
					},
					success: (res) => {
						console.log('res:', res);
						if (res.statusCode == 200) {
							if (res.data.code == 200) {
								
								this.notice.state = myState
								
							} else if (res.data.code == 500) {
								uni.$u.toast(res.data.msg)
							} else {
								uni.$u.toast('系统服务异常，请联系管理员！')
							}
						} else {
							uni.$u.toast('系统服务异常，请联系管理员！')
						}
					},
					fail: (errors) => {
						console.log('errors:', errors);
						uni.$u.toast('服务器错误，请联系管理员！')
					},
				});
			},
			getNoticeDetail() {
			
				uni.request({
					url: 'https://www.gzzyue.com/prod-api/system/campusNotice/' +this.id,
					method: 'GET',
					header: {
						'Authorization': uni.getStorageSync("token") //自定义请求头信息
					},
					success: (res) => {
						console.log('res:', res);
						if (res.statusCode == 200) {
							if (res.data.code == 200) {
								
								this.notice = res.data.data
								
							} else if (res.data.code == 500) {
								uni.$u.toast(res.data.msg)
							} else {
								uni.$u.toast('系统服务异常，请联系管理员！')
							}
						} else {
							uni.$u.toast('系统服务异常，请联系管理员！')
						}
					},
					fail: (errors) => {
						console.log('errors:', errors);
						uni.$u.toast('服务器错误，请联系管理员！')
					},
				});
			},
		}
	}
</script>

<style lang="scss">
.notice-detail-container{
	padding: 10px;
	// border: 1px solid #000;
	// border-radius: 5px;
	.detail{
		.title{
			margin-top: 10px;
		}
		.info{
			font-size: 13px;
			color: orange;
			margin-top: 10px;
			display: flex;
			flex-direction: row;
			justify-content: space-around;
		}
		.stauts{
			margin-top: 10px;
		}
	}
	.content{
		margin-top: 10px;
	}
	.image{
		margin-top: 10px;
		margin-left: 50px;
	}
}
</style>
